<?php
include_once 'class/LogParser.acalss.inc';
include_once 'class/LogReader.aclass.inc';
class TacacsLogParser extends LogParser {
	private $pattern = '%(?P<date>(?P<month>\d{2})/(?P<day>\d{2})/(?P<year>\d{4})),(?P<time>\d{2}:\d{2}:\d{2}),(?P<username>[\w\s./\-@_:]*),(?P<groupname>[\w ]*),(?P<caller_id>\w*),(?P<acct_flags>\w*),(?P<elapsed_time>\d*),(?P<service>\w*),(?P<bytes_in>\d*),(?P<bytes_out>\d*),(?P<paks_in>\d*),(?P<paks_out>\d*),(?P<task_id>\d*),(?P<addr>(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}))?,(?P<nas_portname>\w*\d*(/\d)*),(?P<nas_ip_address>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}),(?P<cmd>\w*)%';
	
	protected function parser($log) {
		$matches = null;
		if(0 === preg_match($this->pattern, $log, $matches))
			return false;
		// <paks_out><task_id><addr><NAS_portname><NAS_IP_Address><cmd>)
		$res = array();
		$res['date']=$matches['date'];
		$res['day']=$matches['day'];
		$res['month']=$matches['month'];
		$res['year']=$matches['year'];
		$res['time'] = $matches['time'];
		$res['username']= $matches['username'];
		$res['groupname'] = $matches['groupname'];
		$res['caller_id'] = $matches['caller_id'];
		$res['acct_flags'] = $matches['acct_flags'];
		$res['elapsed_time'] = $matches['elapsed_time'];
		$res['service'] = $matches['service'];
		$res['bytes_in'] = $matches['bytes_in'];
		$res['bytes_out'] = $matches['bytes_out'];
		$res['paks_in'] = $matches['paks_in'];
		$res['paks_out'] = $matches['paks_out'];
		$res['task_id'] = $matches['task_id'];
		$res['addr'] = $matches['addr'];
		$res['nas_portname']= $matches['nas_portname'];
		$res['nas_ip_address']= $matches['nas_ip_address'];
		$res['cmd']= $matches['cmd'];
		return $res;
	}
	public function getDBVersion($log) {
		$res = array(
			'date'=> $log['year']."-".$log['month']."-".$log['day']." ".$log['time'],
			'username'=> $log['username'],
			'groupname'=> $log['groupname'],
			'caller_id'=> $log['caller_id'] ,
			'acct_flags'=> $log['acct_flags'],
			'elapsed_time'=> $log['elapsed_time'] ,
			'service'=> $log['service'],
			'bytes_in'=> $log['bytes_in'] ,
			'bytes_out'=> $log['bytes_out'],
			'paks_in'=> $log['paks_in'] ,
			'paks_out'=> $log['paks_out'],
			'task_id'=> $log['task_id'],
			'addr'=> $log['addr'],
			'nas_portname'=> $log['nas_portname'],
			'nas_ip_address'=> $log['nas_ip_address'],
			'cmd'=> $log['cmd']
			
	);
	return $res;
	}
	
public function getName() {
		return 'tacacs';
	}
}
?>